const tencentmap = {
  markers: [],
  init(){
    this.map = new qq.maps.Map(document.getElementById("container"), {
      center: new qq.maps.LatLng(39.916527, 116.397128),      // 地图的中心地理坐标。
      zoom: 13                                                 // 地图的中心地理坐标。
    });
  },
  cityService(callback) {
    let that = this;
    let service = new qq.maps.CityService({
      complete: function (result) {
        if (callback) {
          callback(result);
        } else {
          that.map.setCenter(result.detail.latLng);
          let marker = new qq.maps.Marker({
            position: result.detail.latLng,
            animation: qq.maps.MarkerAnimation.DROP,
            map: that.map,
            content: result.detail.name
          });
          that.markers.push(marker);
        }
      },
      error: function (response) {
        alert(response);
      }
    });
    return service;
  },
  clearOverlays(markers) {
    if (markers) {
      for (let i in markers) {
        markers[i].setMap(null);
      }
    } else {
      for (let i in this.markers) {
        this.markers[i].setMap(null);
      }
    }
  }
};

export default tencentmap;
